#!/usr/bin/env python

# kupack.py
#
# Written by Joseph Ku <chiehfang.ku@gmail.com>
# All rights reserved.

import sys
import subprocess
import os

def main(args):

    distribution_name = os.popen('lsb_release -i').read()
    distribution_release = os.popen('lsb_release -r').read()
    
    distribution_id = distribution_name.split()[2].lower() + '_' + distribution_release.split()[1]
    print 'Distribution ID: ' + distribution_id

    packname = args[1]

    if packname == 'vim':
        print('Installing Vim related packages...')
        subprocess.call('sudo apt-get install vim vim-addon-manager vim-scripts', shell=True)

    elif packname == 'tools':
        print('Installing useful tools packages...')
        subprocess.call('sudo apt-get install dvtm meld minicom', shell=True)
       
    elif packname == 'android':
        print('Installing Android related packages...')
        subprocess.call('sudo apt-get install git-core gnupg sun-java5-jdk flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev valgrind', shell=True)

    elif packname == 'gcc':
        print('Installing GCC related packages...')
        subprocess.call('sudo apt-get install bash binutils bison dejagnu flex gcc g++ gnat make tar tcl expect gperf autoconf automake texinfo gettext gfortran gcj autogen gawk libgmp3-dev libmpfr-dev libqtgui4 libqt4-dev', shell=True)

    elif packname == 'medibuntu':
        print('Installing Medibuntu repository setting...')
        subprocess.call('sudo wget http://www.medibuntu.org/sources.list.d/`lsb_release -cs`.list --output-document=/etc/apt/sources.list.d/medibuntu.list && sudo apt-get -q update && sudo apt-get --yes -q --allow-unauthenticated install medibuntu-keyring && sudo apt-get -q update', shell=True)

	if distribution_id == 'ubuntu_9.04':
        	subprocess.call('sudo wget http://www.medibuntu.org/sources.list.d/jaunty.list --output-document=/etc/apt/sources.list.d/medibuntu.list', shell=True)
        elif distribution_id == 'ubuntu_8.04':
        	subprocess.call('sudo wget http://www.medibuntu.org/sources.list.d/hardy.list --output-document=/etc/apt/sources.list.d/medibuntu.list', shell=True)
        subprocess.call('sudo apt-get update && sudo apt-get install medibuntu-keyring && sudo apt-get update', shell=True)
   
    elif packname == 'convert-mp4':
        print('Installing related package for converting to MP4 file...')
        subprocess.call('sudo apt-get install mencoder mplayer gpac faac aacplusenc normalize-audio dvdrip', shell=True)
 
    else:
        print('Wrong package name.')
        

    print('Done.')

    return 0




if __name__ == '__main__':
    exit(main(sys.argv[0:]))



